package de.gameduell.framework.security {

	public class SecureNumber {

		private static var _cheatFlag:Boolean = false;
		private var value:Number;
		private var secureValue:Array;
		private var sign:Number;
		private var multi:Number;

		public function SecureNumber(iniValue:int) {
			value = iniValue;
			secureValue = new Array();
			setValue(iniValue);
		}

		public static function get cheatFlag():Boolean {
			return _cheatFlag;
		}

		public function addValue(aNewValue:int):void {
			setValue(getValue() * sign + aNewValue);
		}

		public function setValue(aNewValue:int):void {	
			value = aNewValue;
			secureValue = new Array();
			sign = aNewValue < 0 ? -1 : 1;
			aNewValue *= sign;
			secureValue[aNewValue - 1] = "";	
		}

		public function getValue():int {
			if(value > secureValue.length) {
				_cheatFlag = true;
			}
			return secureValue.length * sign;
		}

		private function getMultiplicator(aNum:int):int { 
			if(aNum != 0) {
				var currMulti:int = 1;
				while(aNum % (currMulti * 10) == 0) {
					currMulti *= 10;
				}
				return currMulti;
			}else {
				return 0;
			}
		}

		public function toString():String {
			return String(getValue() * sign);
		}
	}
}